﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;
using System.IO.IsolatedStorage;
using System.Xml;
using System.IO;
using System.Collections.Generic;

namespace TAXILISM.Class
{
    public class LocationAllow
    {
        public void putAllow(string stat)
        {
            string fileName = "locationallow.xaml";
            XElement elm;

            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(fileName, FileMode.Create, myIsolatedStorage))
                {
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    using (XmlWriter writer = XmlWriter.Create(isoStream, settings))
                    {
                        writer.WriteStartElement("locationallow");
                        writer.WriteStartElement("status");
                        writer.WriteString(stat.ToString());
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                        // Ends the document
                        writer.WriteEndDocument();
                        // Write the XML to the file.
                        writer.Flush();
                    }
                }
                //}
            }

        }

        public string status;
        public void getAllow()
        {
            try
            {
                IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
                IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("locationallow.xaml", FileMode.Open, FileAccess.Read);
                using (StreamReader reader = new StreamReader(fileStream))
                {    //Visualize the text data in a TextBlock text
                    XElement eld = XElement.Parse(reader.ReadToEnd());
                    //MessageBox.Show("");
                    while (eld.FirstNode as XElement != null)
                    {
                        string idAdd = Convert.ToString((eld.FirstNode as XElement).Value);
                        (eld.FirstNode as XElement).Remove();
                        status = idAdd;
                    }
                }
            }
            catch (Exception)
            {
            }
        }

        public void clearRecent()
        {
            string fileName = "locationallow.xaml";
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(fileName, FileMode.Create, myIsolatedStorage))
                {
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent = true;
                    using (XmlWriter writer = XmlWriter.Create(isoStream, settings))
                    {
                        writer.WriteStartElement("taxirecent");
                        writer.WriteEndElement();
                        // Ends the document
                        writer.WriteEndDocument();
                        // Write the XML to the file.
                        writer.Flush();
                    }
                }
                //}
            }
        }
    }
}
